<?php
namespace app\common\model;
use think\Model;

class FirmModel extends Model{
    protected  $name = 'firm';
    protected  $pk   = 'firm_id';

    public static function onBeforeInsert($model)
    {
        $model->set("create_ip", request()->ip());
    }
    public function setExpireTimeAttr($value){
        return strtotime($value);
    }
    public function getExpireTimeAttr($value){
        return date('Y-m-d',$value);
    }
    
    public function detail()
    {
        return $this->hasOne(FirmDetailModel::class, 'firm_id')->bind(['logo','company_name','tel','address','info','lng','lat']);
    }
    public function style()
    {
        return $this->hasOne(FirmStyleModel::class, 'firm_id')->bind(['global','card','menu','page']);
    }
    public function kefu(){
        return $this->hasOne(CustomerServiceModel::class, 'customer_service_id','customer_service_id');
    }
}